<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="baidu-site-verification" content="zD47G9xe42" />


<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="uiste个人博客网站,uiste,uiste博客,PHP,运维,Hexo,技术博客" />





  <link rel="alternate" href="/atom.xml" title="uiste" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="Stay Hungry，Stay Foolish">
<meta property="og:type" content="website">
<meta property="og:title" content="uiste">
<meta property="og:url" content="http://blog.uiste.com/page/5/index.html">
<meta property="og:site_name" content="uiste">
<meta property="og:description" content="Stay Hungry，Stay Foolish">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="uiste">
<meta name="twitter:description" content="Stay Hungry，Stay Foolish">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://blog.uiste.com/page/5/"/>

  <title>
 
  uiste - Stay Hungry，Stay Foolish 

</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  



  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?b58b87af012832b8ae35e33bb45b44fa";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container one-collumn sidebar-position-left 
   page-home 
 ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">uiste</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">uiste个人博客</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      

            <li class="menu-item menu-item-search"> <a title="把这个链接拖到你的Chrome收藏夹工具栏中" href='javascript:(function() {
    function c() {
        var e = document.createElement("link");
        e.setAttribute("type", "text/css");
        e.setAttribute("rel", "stylesheet");
        e.setAttribute("href", f);
        e.setAttribute("class", l);
        document.body.appendChild(e)
    }
 
    function h() {
        var e = document.getElementsByClassName(l);
        for (var t = 0; t < e.length; t++) {
            document.body.removeChild(e[t])
        }
    }
 
    function p() {
        var e = document.createElement("div");
        e.setAttribute("class", a);
        document.body.appendChild(e);
        setTimeout(function() {
            document.body.removeChild(e)
        }, 100)
    }
 
    function d(e) {
        return {
            height : e.offsetHeight,
            width : e.offsetWidth
        }
    }
 
    function v(i) {
        var s = d(i);
        return s.height > e && s.height < n && s.width > t && s.width < r
    }
 
    function m(e) {
        var t = e;
        var n = 0;
        while (!!t) {
            n += t.offsetTop;
            t = t.offsetParent
        }
        return n
    }
 
    function g() {
        var e = document.documentElement;
        if (!!window.innerWidth) {
            return window.innerHeight
        } else if (e && !isNaN(e.clientHeight)) {
            return e.clientHeight
        }
        return 0
    }
 
    function y() {
        if (window.pageYOffset) {
            return window.pageYOffset
        }
        return Math.max(document.documentElement.scrollTop, document.body.scrollTop)
    }
 
    function E(e) {
        var t = m(e);
        return t >= w && t <= b + w
    }
 
    function S() {
        var e = document.createElement("audio");
        e.setAttribute("class", l);
        e.src = i;
        e.loop = false;
        e.addEventListener("canplay", function() {
            setTimeout(function() {
                x(k)
            }, 500);
            setTimeout(function() {
                N();
                p();
                for (var e = 0; e < O.length; e++) {
                    T(O[e])
                }
            }, 15500)
        }, true);
        e.addEventListener("ended", function() {
            N();
            h()
        }, true);
        e.innerHTML = " <p>If you are reading this, it is because your browser does not support the audio element. We recommend that you get a new browser.</p> <p>";
        document.body.appendChild(e);
        e.play()
    }
 
    function x(e) {
        e.className += " " + s + " " + o
    }
 
    function T(e) {
        e.className += " " + s + " " + u[Math.floor(Math.random() * u.length)]
    }
 
    function N() {
        var e = document.getElementsByClassName(s);
        var t = new RegExp("\\b" + s + "\\b");
        for (var n = 0; n < e.length; ) {
            e[n].className = e[n].className.replace(t, "")
        }
    }
 
    var e = 30;
    var t = 30;
    var n = 350;
    var r = 350;
    var i = "//s3.amazonaws.com/moovweb-marketing/playground/harlem-shake.mp3";
    var s = "mw-harlem_shake_me";
    var o = "im_first";
    var u = ["im_drunk", "im_baked", "im_trippin", "im_blown"];
    var a = "mw-strobe_light";
    var f = "//s3.amazonaws.com/moovweb-marketing/playground/harlem-shake-style.css";
    var l = "mw_added_css";
    var b = g();
    var w = y();
    var C = document.getElementsByTagName("*");
    var k = null;
    for (var L = 0; L < C.length; L++) {
        var A = C[L];
        if (v(A)) {
            if (E(A)) {
                k = A;
                break
            }
        }
    }
    if (A === null) {
        console.warn("Could not find a node of the right size. Please try a different page.");
        return
    }
    c();
    S();
    var O = [];
    for (var L = 0; L < C.length; L++) {
        var A = C[L];
        if (v(A)) {
            O.push(A)
        }
    }
})()    '>High</a> </li>

    </ul>
  

 
    <div class="site-search">
      
  <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>


    </div>
   
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/20160930-1.html" itemprop="url">
                  laravel - Composer 安装
                </a>
              
            
          </h1>
        

        <div class="post-meta">
        
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-09-30T13:48:18+08:00" content="2016-09-30">
              2016-09-30
            </time>
          </span>

          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/20160930-1.html#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="20160930-1.html" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h1 id="Composer-安装（一）"><a href="#Composer-安装（一）" class="headerlink" title="Composer 安装（一）"></a>Composer 安装（一）</h1><h3 id="一、简介"><a href="#一、简介" class="headerlink" title="一、简介"></a>一、简介</h3><p>Composer 是 PHP 用来管理依赖（dependency）关系的工具。你可以在自己的项目中声明所依赖的外部工具库（libraries），Composer 会帮你安装这些依赖的库文件。</p>
<h3 id="二、为什么要使用Composer"><a href="#二、为什么要使用Composer" class="headerlink" title="二、为什么要使用Composer"></a>二、为什么要使用Composer</h3><p>你有一个项目依赖于若干个库。<br>其中一些库依赖于其他库。<br>你声明你所依赖的东西。<br>Composer 会找出哪个版本的包需要安装，并安装它们（将它们下载到你的项目中）。</p>
<h3 id="三、安装方式"><a href="#三、安装方式" class="headerlink" title="三、安装方式"></a>三、安装方式</h3><p>通用安装方式（Win、Linux、Mac都能用），使用composer.phar文件（其实就是下载composer.phar文件，不需要翻墙）</p>
<ul>
<li><p>直接下载composer.phar文件<br><a href="https://getcomposer.org/download/" target="_blank" rel="external">composer下载</a></p>
</li>
<li><p>打开命令行并执行下列命令安装最新版本的 Composer</p>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">uiste:~ uiste$ php -r &quot;readfile(&apos;https://getcomposer.org/installer&apos;);&quot; | php</div><div class="line">All settings correct for using Composer</div><div class="line">Downloading 1.2.1...</div><div class="line"></div><div class="line">Composer successfully installed to: /Users/uiste/composer.phar</div><div class="line">Use it: php composer.phar</div></pre></td></tr></table></figure>
<blockquote>
<p>这将检查一些PHP的设置，然后下载composer.phar到当前工作目录中。这是Composer的二进制文件。这是一个PHAR 包（PHP 的归档），这是PHP的归档格式可以帮助用户在命令行中执行一些操作。</p>
</blockquote>
<ul>
<li>检测是否安装成功<br>输入如下命令，如果成功则出现以下信息：</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">uiste:~ uiste$ php composer.phar</div><div class="line">   ______</div><div class="line">  / ____/___  ____ ___  ____  ____  ________  _____</div><div class="line"> / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/</div><div class="line">/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /</div><div class="line">\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/</div><div class="line">                    /_/</div><div class="line">Composer version 1.2.1 2016-09-12 11:27:19</div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">___</div></pre></td></tr></table></figure>
<h3 id="局部安装和全局安装"><a href="#局部安装和全局安装" class="headerlink" title="局部安装和全局安装"></a>局部安装和全局安装</h3><p>四、局部安装</p>
<p>上述下载Composer的过程正确执行完毕后，可以将composer.phar文件复制到任意目录（比如项目根目录下），然后通过 php composer.phar 指令即可使用Composer了！</p>
<p>五、全局安装</p>
<p>全局安装是将Composer安装到系统环境变量PATH所包含的路径下面，然后就能够在命令行窗口中直接执行composer命令了。</p>
<ol>
<li>Mac或Linux系统</li>
</ol>
<p>打开命令行窗口并执行如下命令将前面下载的composer.phar文件移动到 /usr/local/bin/ 目录下面：</p>
<p>sudo mv composer.phar /usr/local/bin/composer  </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">uiste:~ uiste$ sudo mv composer.phar /usr/local/bin/composer</div><div class="line"></div><div class="line">WARNING: Improper use of the sudo command could lead to data loss</div><div class="line">or the deletion of important system files. Please double-check your</div><div class="line">typing when using sudo. Type &quot;man sudo&quot; for more information.</div><div class="line"></div><div class="line">To proceed, enter your password, or type Ctrl-C to abort.</div><div class="line"></div><div class="line">Password:</div></pre></td></tr></table></figure>
<ol>
<li>Win系统</li>
</ol>
<p>找到并进入PHP的安装目录（和你在命令行中执行的php指令应该是同一套PHP）。<br>将 composer.phar 复制到PHP的安装目录下面，也就是和 php.exe 在同一级目录。<br>在 PHP 安装目录下新建一个 composer.bat 文件，并将下列代码保存到此文件中。<br>@php “%~dp0composer.phar” %*</p>
<ol>
<li>检测全局安装是否成功</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">uiste:~ uiste$ composer --version</div><div class="line">Composer version 1.2.1 2016-09-12 11:27:19</div></pre></td></tr></table></figure>
<h1 id="Composer-中国全量镜像（二）"><a href="#Composer-中国全量镜像（二）" class="headerlink" title="Composer 中国全量镜像（二）"></a>Composer 中国全量镜像（二）</h1><p>为什么要使用Composer中国全量镜像？</p>
<p>一般情况下，安装包的数据（主要是 zip 文件）是从 github.com 上下载的，安装包的元数据是从 packagist.org 上下载的。</p>
<p>然而，由于众所周知的原因，国外的网站连接速度很慢，并且随时可能被“墙”。</p>
<p>“Composer 中国全量镜像”所做的就是缓存所有安装包和元数据到国内的机房并通过国内的 CDN 进行加速，这样就不必再去向国外的网站发起请求，这样我们使用Composer时就会更加快速、稳定。</p>
<h3 id="查看当前镜像地址"><a href="#查看当前镜像地址" class="headerlink" title="查看当前镜像地址"></a>查看当前镜像地址</h3><p>在命令行输入如下命令，即可查看镜像地址：<code>composer config -l -g</code> 查看所有全局配置</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">uiste:~ uiste$ composer config -l -g</div><div class="line">[repositories.packagist.type] composer</div><div class="line">[repositories.packagist.url] https?://packagist.org</div><div class="line">[repositories.packagist.allow_ssl_downgrade] true</div></pre></td></tr></table></figure>
<h3 id="启用中国全量镜像服务"><a href="#启用中国全量镜像服务" class="headerlink" title="启用中国全量镜像服务"></a>启用中国全量镜像服务</h3><p>启用中国全量镜像服务有两种方式，具体配置方法如下：</p>
<ol>
<li><p>系统全局配置：<br>即将配置信息添加到 Composer 的全局配置文件 config.json 中。修改composer的全局配置文件（推荐方式），打开命令行并执行如下命令：<br><code>uiste:~ uiste$ composer config -g repo.packagist composer https://packagist.phpcomposer.com</code></p>
</li>
<li><p>单个项目配置：<br>即将将配置信息添加到某个项目的 composer.json 文件中。修改当前项目的composer.json配置文件有两种方式，最后都是向文件中添加如下配置信息：</p>
</li>
</ol>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">&quot;repositories&quot;: &#123;</div><div class="line">    &quot;packagist&quot;: &#123;</div><div class="line">        &quot;type&quot;: &quot;composer&quot;,</div><div class="line">        &quot;url&quot;: &quot;https://packagist.phpcomposer.com&quot;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>2.1 打开命令行并进入项目的根目录（也就是 composer.json 文件所在目录），执行如下命令：<br><code>composer config repo.packagist composer https://packagist.phpcomposer.com</code><br>该命令将会在当前项目中的 composer.json 文件的末尾自动添加镜像的配置信息<br>2.2 手动向composer.json文件中添加以上信息</p>
<h1 id="Composer-常用命令总结（三）"><a href="#Composer-常用命令总结（三）" class="headerlink" title="Composer 常用命令总结（三）"></a>Composer 常用命令总结（三）</h1><h3 id="init（初始化）"><a href="#init（初始化）" class="headerlink" title="init（初始化）"></a>init（初始化）</h3><p>该命令用于创建 composer.json 文件，并进行基础信息配置：<br><code>uiste:~ uiste$ composer init</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">uiste:~ uiste$ composer init</div><div class="line"></div><div class="line">                                            </div><div class="line">  Welcome to the Composer config generator  </div><div class="line">                                            </div><div class="line"></div><div class="line"></div><div class="line">This command will guide you through creating your composer.json config.</div><div class="line"></div><div class="line">Package name (&lt;vendor&gt;/&lt;name&gt;) [uiste/uiste]:</div></pre></td></tr></table></figure>
<p>可以配置Package name、Description、Author、Minimum、Package Type、License、dependencies 及 dev dependencies 信息。</p>
<p>完成后配置文件内容如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">&#123;</div><div class="line">    &quot;name&quot;: &quot;test/test&quot;,</div><div class="line">    &quot;description&quot;: &quot;test init&quot;,</div><div class="line">    &quot;type&quot;: &quot;library&quot;,</div><div class="line">    &quot;license&quot;: &quot;License Description&quot;,</div><div class="line">    &quot;authors&quot;: [</div><div class="line">        &#123;</div><div class="line">            &quot;name&quot;: &quot;mayanlong&quot;,</div><div class="line">            &quot;email&quot;: &quot;json_vip@163.com&quot;</div><div class="line">        &#125;</div><div class="line">    ],</div><div class="line">    &quot;require&quot;: &#123;&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h3 id="search（搜索）"><a href="#search（搜索）" class="headerlink" title="search（搜索）"></a>search（搜索）</h3><p>根据名称搜索相关的包，成功后会列出符合的相关包的信息，本处以搜索 monolog 为例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">$ composer search monolog </div><div class="line">monolog/monolog Sends your logs to files, sockets, inboxes, databases and various web services</div><div class="line">kdyby/monolog Integration of Monolog into Nette Framework</div></pre></td></tr></table></figure>
<h3 id="show（详情）"><a href="#show（详情）" class="headerlink" title="show（详情）"></a>show（详情）</h3><p>根据包的名称，列出包的相关信息，本处以查看 monolog/monolog 为例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">$ composer show -all monolog/monolog</div><div class="line">name     : monolog/monolog</div><div class="line">descrip. : Sends your logs to files, sockets, inboxes, databases and various web services</div><div class="line">keywords : log, logging, psr-3</div><div class="line">versions : dev-master, 2.0.x-dev, 1.x-dev, 1.21.0, 1.20.0, 1.19.0, 1.18.2, 1.18.1, 1.18.0, 1.17.2, 1.17.1, 1.17.0, 1.16.0, 1.15.0, 1.14.0, 1.13.1, 1.13.0, 1.12.0, 1.11.0, 1.10.0, 1.9.1, 1.9.0, 1.8.0, 1.7.0, 1.6.0, 1.5.0, 1.4.1, 1.4.0, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.2, 1.0.1, 1.0.0, 1.0.0-RC1</div></pre></td></tr></table></figure>
<p>想查看更多信息，就亲自将该命令复制到命令行执行吧。</p>
<h3 id="install-安装"><a href="#install-安装" class="headerlink" title="install (安装)"></a>install (安装)</h3><p>先在 composer.json 配置中添加一个 monolog/monolog 依赖库，如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">&#123;</div><div class="line">    &quot;name&quot;: &quot;test/test&quot;,</div><div class="line">    &quot;description&quot;: &quot;test init&quot;,</div><div class="line">    &quot;type&quot;: &quot;library&quot;,</div><div class="line">    &quot;license&quot;: &quot;License Description&quot;,</div><div class="line">    &quot;authors&quot;: [</div><div class="line">        &#123;</div><div class="line">            &quot;name&quot;: &quot;mayanlong&quot;,</div><div class="line">            &quot;email&quot;: &quot;json_vip@163.com&quot;</div><div class="line">        &#125;</div><div class="line">    ],</div><div class="line">    &quot;require&quot;: &#123;</div><div class="line">        &quot;monolog/monolog&quot;: &quot;1.21.*&quot;,</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>然后通过如下命令进行安装依赖</p>
<p><code>$ composer install</code></p>
<h3 id="update-（更新）"><a href="#update-（更新）" class="headerlink" title="update （更新）"></a>update （更新）</h3><p>如果我们新增或者删除了某个依赖，可以通过如下命令进行更新</p>
<p><code>$ composer update</code></p>
<h3 id="require-（申明依赖）"><a href="#require-（申明依赖）" class="headerlink" title="require （申明依赖）"></a>require （申明依赖）</h3><p>我们也可以用命令直接添加依赖，执行该命令后将自动下载，命令如下：</p>
<p><code>$ composer require symfony/http-foundation</code></p>
<p><a href="http://www.phpcomposer.com/" target="_blank" rel="external">composer中文网</a></p>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/20160927-1.html" itemprop="url">
                  PHP-验证码图片排错
                </a>
              
            
          </h1>
        

        <div class="post-meta">
        
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-09-27T14:44:17+08:00" content="2016-09-27">
              2016-09-27
            </time>
          </span>

          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/20160927-1.html#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="20160927-1.html" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>第一步：如果看到不显示验证码，直接输入验证码的地址来排错</p>
<p>第二步：将header()函数注释掉就可能会显示错误</p>
<p>第三步：查看图片源码<br>在图片二进制代码前不能出现任何字符，包括空白字符</p>
<p>第四步：在header()前面添加ob_clean()</p>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/20160926-1.html" itemprop="url">
                  COOKIE 和 SESSION
                </a>
              
            
          </h1>
        

        <div class="post-meta">
        
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-09-26T19:31:59+08:00" content="2016-09-26">
              2016-09-26
            </time>
          </span>

          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/20160926-1.html#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="20160926-1.html" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <blockquote>
<p>思考：A页面中如何访问B页面中的变量<br>包含文件<br>get传递或post传递<br>cookie：cookie是小的信息包。</p>
</blockquote>
<h1 id="Cookie"><a href="#Cookie" class="headerlink" title="Cookie"></a>Cookie</h1><h3 id="cookie的原理"><a href="#cookie的原理" class="headerlink" title="cookie的原理"></a>cookie的原理</h3><p>浏览器—-http请求（无值）——–&gt;服务器<br>浏览器&lt;—响应头中传递cookie——-服务器<br>浏览器—-再次发送http请求（有值）–&gt;服务器</p>
<ol>
<li><strong>请求头：客户端请求服务器的时候，告知服务器客户端的信息</strong></li>
<li><strong>响应头：服务器响应客户端的时候，告知客户端服务器的信息</strong></li>
</ol>
<h3 id="长连接"><a href="#长连接" class="headerlink" title="长连接"></a>长连接</h3><p>在多个http请求之间，TCP连接不断开称为长连接，默认是5秒。<br>长连接过程中，可以建立多次<em>http请求</em>与<em>http响应</em></p>
<h3 id="cookie保存在客户端"><a href="#cookie保存在客户端" class="headerlink" title="cookie保存在客户端"></a>cookie保存在客户端</h3><h3 id="设置cookie"><a href="#设置cookie" class="headerlink" title="设置cookie"></a>设置cookie</h3><p>语法：setcookie(名字,值,过期时间,有效目录,子域名)</p>
<p><code>bool setcookie ( string $name [, string $value = &quot;&quot; [, int $expire = 0 [, string $path = &quot;&quot; [, string $domain = &quot;&quot; [, bool $secure = false [, bool $httponly = false ]]]]]] )</code></p>
<h3 id="临时性cookie"><a href="#临时性cookie" class="headerlink" title="临时性cookie"></a>临时性cookie</h3><p>关闭浏览器cookie就消失</p>
<h3 id="永久性cookie"><a href="#永久性cookie" class="headerlink" title="永久性cookie"></a>永久性cookie</h3><ul>
<li>[ ] 下次自动登录    （案例）</li>
</ul>
<blockquote>
<p>在临时性cookie的基础上加上一个过期时间就成了永久性cookie，过期时间是一个时间戳<br>永久性cookie保存在浏览器上，换个浏览器就不行了</p>
</blockquote>
<h3 id="cookie保存的数据类型"><a href="#cookie保存的数据类型" class="headerlink" title="cookie保存的数据类型"></a>cookie保存的数据类型</h3><p>cookie不能存放bool型数据，true=&gt;1 false=&gt;delete<br>cookie不能存放数组和对象<br><strong>cookie中只能存放字符串</strong></p>
<h3 id="删除cookie"><a href="#删除cookie" class="headerlink" title="删除cookie"></a>删除cookie</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">Set-Cookie:</div><div class="line">name=uiste; expires=Mon, 26-Sep-2016 12:07:11 GMT; Max-Age=100</div><div class="line">sex=man; expires=Mon, 26-Sep-2016 12:07:11 GMT; Max-Age=100</div><div class="line">age=24; expires=Mon, 26-Sep-2016 12:07:11 GMT; Max-Age=100</div><div class="line">name=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0</div><div class="line">sex=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0</div><div class="line">age=</div></pre></td></tr></table></figure>
<h3 id="cookie支持下标"><a href="#cookie支持下标" class="headerlink" title="cookie支持下标"></a>cookie支持下标</h3><p>cookie在浏览器上没有数组的概念，只是浏览器请求到服务器，PHP将同名的变量转成数组</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">&lt;?php</div><div class="line">//cookie不支持数组，但是支持下标</div><div class="line">setcookie(&apos;stu[0]&apos;,&apos;tom&apos;);</div><div class="line">setcookie(&apos;stu[1]&apos;,&apos;berry&apos;);</div><div class="line">setcookie(&apos;stu[2]&apos;,&apos;ketty&apos;);</div><div class="line">?&gt;</div></pre></td></tr></table></figure>
<h3 id="cookie有效目录"><a href="#cookie有效目录" class="headerlink" title="cookie有效目录"></a>cookie有效目录</h3><p>默认情况下，cookie只能在当前目录和子级目录中有效<br>如果要在整个网站中有效，就要设置有效目录，‘/’表示整站有效<br><code>setcookie(&#39;name&#39;,&#39;tom&#39;,0,&#39;/&#39;)</code></p>
<h3 id="cookie支持子域名"><a href="#cookie支持子域名" class="headerlink" title="cookie支持子域名"></a>cookie支持子域名</h3><p>默认情况下，cookie是区分子域名的。一个子域名就代替一个独立的服务器</p>
<h3 id="cookie的缺点"><a href="#cookie的缺点" class="headerlink" title="cookie的缺点"></a>cookie的缺点</h3><ol>
<li>信息保存在本地，安全性低</li>
<li>只能保存字符串，不能保存数组和对象，可控性差</li>
<li>数据保存在头信息中，增加请求时的数据负载</li>
<li>一般浏览器对cookie的要求是不能高于4K</li>
</ol>
<h1 id="session-会话"><a href="#session-会话" class="headerlink" title="session(会话)"></a>session(会话)</h1><p>将数据存储到服务器端，每个客户一个空间，通过编号访问自己的数据</p>
<ul>
<li>第一次访问服务器，服务器给客户端分配一个编号</li>
<li>通过编号来访问服务器保存的数据</li>
<li>每个客户只能访问自己的数据<br><strong>session是基于cookie的技术</strong></li>
</ul>
<h3 id="session的操作"><a href="#session的操作" class="headerlink" title="session的操作"></a>session的操作</h3><ol>
<li>要使用会话必须显示的开启会话，<code>session_start()</code>。默认情况下，会话不会自动开启。</li>
<li>要自动开启会话，在<code>php.ini</code>文件中<code>session.auto_start=1</code>，把0改为1就自动开启了</li>
<li>session_id():会话编号</li>
<li>session_name():会话名称</li>
<li>session可以保存除了资源以外的所有类型的数据</li>
<li>重复开启会话会报错，可以通过<code>@</code>来屏蔽会话</li>
</ol>
<h3 id="session执行过程"><a href="#session执行过程" class="headerlink" title="session执行过程"></a>session执行过程</h3><ol>
<li>使用<code>session_start()</code>从<code>session</code>仓库中加载已经存在的<code>session</code>变量</li>
<li>第一次请求服务器，一个唯一的会话id存储到cookie响应头中</li>
<li>在后面的请求中，会话id保存请求头中，服务器获取请求头的会话id，通过id获取会话的值</li>
<li>页面执行完毕返回到客户端之前，将会话自动保存到服务器的session库中。下次浏览网页可以加载再次使用</li>
</ol>
<h3 id="session的配置"><a href="#session的配置" class="headerlink" title="session的配置"></a>session的配置</h3><h2 id="1-session-save-path：指定session库的路径"><a href="#1-session-save-path：指定session库的路径" class="headerlink" title="1. session.save_path：指定session库的路径  "></a>1. session.save_path：指定session库的路径  </h2><p>session.save_path = “N;/path”, N表示通过N级目录来保存会话，N等于1，就是通过会话的第一个字母创建文件夹；N等于2表示通过两级目录创建文件夹，第一级是第一个字母，第二级是第二个字母。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">; 用于保存/取回数据的控制方式</div><div class="line">session.save_handler=files</div><div class="line">;     session.save_path = &quot;N;/path&quot;</div><div class="line">; 在 save_handler 设为文件时传给控制器的参数， 这是数据文件将保存的路径</div><div class="line">session.save_path=&quot;/Applications/XAMPP/xamppfiles/temp/&quot;</div></pre></td></tr></table></figure>
<h2 id="2-session-name：设置会话名称"><a href="#2-session-name：设置会话名称" class="headerlink" title="2. session.name：设置会话名称"></a>2. session.name：设置会话名称</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">; Name of the session (used as cookie name).</div><div class="line">; http://php.net/session.name</div><div class="line">session.name=PHPSESSID</div></pre></td></tr></table></figure>
<h2 id="3-session-cookie-lifetime：保存会话编号的cookie有效时间"><a href="#3-session-cookie-lifetime：保存会话编号的cookie有效时间" class="headerlink" title="3. session.cookie_lifetime：保存会话编号的cookie有效时间"></a>3. session.cookie_lifetime：保存会话编号的cookie有效时间</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">; Lifetime in seconds of cookie or, if 0, until browser is restarted.</div><div class="line">; http://php.net/session.cookie-lifetime</div><div class="line">session.cookie_lifetime=0</div></pre></td></tr></table></figure>
<h2 id="4-session-cookie-path：保存会话的cookie整站有效"><a href="#4-session-cookie-path：保存会话的cookie整站有效" class="headerlink" title="4. session.cookie_path：保存会话的cookie整站有效"></a>4. session.cookie_path：保存会话的cookie整站有效</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">; The path for which the cookie is valid.</div><div class="line">; http://php.net/session.cookie-path</div><div class="line">session.cookie_path=/</div></pre></td></tr></table></figure>
<h2 id="5-session-cookie-domain：当前域名有效"><a href="#5-session-cookie-domain：当前域名有效" class="headerlink" title="5. session.cookie_domain：当前域名有效"></a>5. session.cookie_domain：当前域名有效</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">; The domain for which the cookie is valid.</div><div class="line">; http://php.net/session.cookie-domain</div><div class="line">session.cookie_domain=</div></pre></td></tr></table></figure>
<h2 id="6-session-save-handler-files：会话按文件格式保存"><a href="#6-session-save-handler-files：会话按文件格式保存" class="headerlink" title="6. session.save_handler = files：会话按文件格式保存"></a>6. session.save_handler = files：会话按文件格式保存</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">; Handler used to store/retrieve data.</div><div class="line">; http://php.net/session.save-handler</div><div class="line">session.save_handler=files</div></pre></td></tr></table></figure>
<h2 id="7-session-hash-function-0：设置session会话的算法"><a href="#7-session-hash-function-0：设置session会话的算法" class="headerlink" title="7. session.hash_function = 0：设置session会话的算法"></a>7. session.hash_function = 0：设置session会话的算法</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">; Select a hash function for use in generating session ids.</div><div class="line">; Possible Values </div><div class="line">;   0  (MD5 128 bits)</div><div class="line">;   1  (SHA-1 160 bits)</div><div class="line">; http://php.net/session.hash-function</div><div class="line">session.hash_function=0</div></pre></td></tr></table></figure>
<h2 id="8-session-hash-bits-per-character-5：每个字符占用的位数"><a href="#8-session-hash-bits-per-character-5：每个字符占用的位数" class="headerlink" title="8. session.hash_bits_per_character = 5：每个字符占用的位数"></a>8. session.hash_bits_per_character = 5：每个字符占用的位数</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">; Define how many bits are stored in each character when converting</div><div class="line">; the binary hash data to something readable.</div><div class="line">; Possible values:</div><div class="line">;   4  (4 bits: 0-9, a-f)</div><div class="line">;   5  (5 bits: 0-9, a-v)</div><div class="line">;   6  (6 bits: 0-9, a-z, A-Z, &quot;-&quot;, &quot;,&quot;)</div><div class="line">; Default Value: 4</div><div class="line">; Development Value: 5</div><div class="line">; Production Value: 5</div><div class="line">; http://php.net/session.hash-bits-per-character</div><div class="line">session.hash_bits_per_character=5</div></pre></td></tr></table></figure>
<h2 id="9-session-gc-maxlifetime-1440：会话过期时间"><a href="#9-session-gc-maxlifetime-1440：会话过期时间" class="headerlink" title="9. session.gc_maxlifetime = 1440：会话过期时间"></a>9. session.gc_maxlifetime = 1440：会话过期时间</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">; After this number of seconds, stored data will be seen as &apos;garbage&apos; and</div><div class="line">; cleaned up by the garbage collection process.</div><div class="line">; http://php.net/session.gc-maxlifetime</div><div class="line">session.gc_maxlifetime=1440</div></pre></td></tr></table></figure>
<h3 id="session-destroy-：销毁会话"><a href="#session-destroy-：销毁会话" class="headerlink" title="session_destroy()：销毁会话"></a>session_destroy()：销毁会话</h3><ol>
<li>删除储存介质中的文件</li>
<li>执行此行，就不会执行会话写入操作了</li>
</ol>
<h1 id="session入库"><a href="#session入库" class="headerlink" title="session入库"></a>session入库</h1><h3 id="新建数据库"><a href="#新建数据库" class="headerlink" title="新建数据库"></a>新建数据库</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">drop table if exists sess;</div><div class="line">create table sess(</div><div class="line">       sess_id varchar(32) primary key comment &apos;会话编号&apos;,</div><div class="line">       sess_value text comment &apos;会话的值&apos;,</div><div class="line">       sess_expires int not null comment &apos;会话产生时间&apos;</div><div class="line">)engine=innodb charset=utf8;</div></pre></td></tr></table></figure>
<h3 id="session-set-save-handler-设置用户自定义会话存储函数"><a href="#session-set-save-handler-设置用户自定义会话存储函数" class="headerlink" title="session_set_save_handler()设置用户自定义会话存储函数"></a>session_set_save_handler()设置用户自定义会话存储函数</h3><p><code>bool session_set_save_handler ( callable $open , callable $close , callable $read , callable $write , callable $destroy , callable $gc [, callable $create_sid ] )</code></p>
<ul>
<li>open:开启会话</li>
<li>close:关闭会话</li>
<li>read:读取会话</li>
<li>write:写入会话</li>
<li>destroy:销毁会话</li>
<li>gc:销毁会话</li>
</ul>
<p>执行session_destroy()的时候才调用destroy()函数</p>
<blockquote>
<p>为什么gc不执行?</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line">; Defines the probability that the &apos;garbage collection&apos; process is started</div><div class="line">; on every session initialization. The probability is calculated by using</div><div class="line">; gc_probability/gc_divisor. Where session.gc_probability is the numerator</div><div class="line">; and gc_divisor is the denominator in the equation. Setting this value to 1</div><div class="line">; when the session.gc_divisor value is 100 will give you approximately a 1% chance</div><div class="line">; the gc will run on any give request.</div><div class="line">; Default Value: 1</div><div class="line">; Development Value: 1</div><div class="line">; Production Value: 1</div><div class="line">; http://php.net/session.gc-probability</div><div class="line">session.gc_probability=1</div><div class="line"></div><div class="line">; Defines the probability that the &apos;garbage collection&apos; process is started on every</div><div class="line">; session initialization. The probability is calculated by using the following equation: </div><div class="line">; gc_probability/gc_divisor. Where session.gc_probability is the numerator and</div><div class="line">; session.gc_divisor is the denominator in the equation. Setting this value to 1</div><div class="line">; when the session.gc_divisor value is 100 will give you approximately a 1% chance</div><div class="line">; the gc will run on any give request. Increasing this value to 1000 will give you</div><div class="line">; a 0.1% chance the gc will run on any give request. For high volume production servers,</div><div class="line">; this is a more efficient approach.</div><div class="line">; Default Value: 100</div><div class="line">; Development Value: 1000</div><div class="line">; Production Value: 1000</div><div class="line">; http://php.net/session.gc-divisor</div><div class="line">session.gc_divisor=1000</div></pre></td></tr></table></figure>
<blockquote>
<p>session.gc_probability=1   概率<br>session.gc_divisor=1000    除数<br>执行垃圾回收的概率是：1/1000</p>
</blockquote>
<h3 id="session入库-1"><a href="#session入库-1" class="headerlink" title="session入库"></a>session入库</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div></pre></td><td class="code"><pre><div class="line">&lt;?php</div><div class="line">header(&apos;content-type:text/html;charset=utf-8&apos;);</div><div class="line">//开启会话</div><div class="line">function open() &#123;</div><div class="line">	mysql_connect(&apos;localhost&apos;,&apos;root&apos;,&apos;aa&apos;);</div><div class="line">	mysql_query(&apos;set names utf8&apos;);</div><div class="line">	mysql_query(&apos;use php5&apos;);</div><div class="line">&#125;</div><div class="line">//关闭会话</div><div class="line">function close() &#123;</div><div class="line">&#125;</div><div class="line">/**</div><div class="line">*读取会话</div><div class="line">*@param $sess_id string 会话编号</div><div class="line">*/</div><div class="line">function read($sess_id) &#123;</div><div class="line">	$sql=&quot;select sess_value from sess where sess_id=&apos;$sess_id&apos;&quot;;</div><div class="line">	$rs=mysql_query($sql);</div><div class="line">	if($rows=mysql_fetch_row($rs))</div><div class="line">		return $rows[0];</div><div class="line">	return &apos;&apos;;</div><div class="line">&#125;</div><div class="line">/**</div><div class="line">*写入会话</div><div class="line">*@param $sess_id string 会话编号</div><div class="line">*@param $sess_value string 会话值</div><div class="line">*/</div><div class="line">function write($sess_id,$sess_value) &#123;</div><div class="line">	$expires=time();</div><div class="line">	$sql=&quot;insert into sess values (&apos;$sess_id&apos;,&apos;$sess_value&apos;,$expires) on duplicate key update sess_value=&apos;$sess_value&apos;,sess_expires=$expires&quot;;</div><div class="line">	return mysql_query($sql);</div><div class="line">&#125;</div><div class="line">/**</div><div class="line">*销毁会话</div><div class="line">*/</div><div class="line">function destroy($sess_id) &#123;</div><div class="line">	$sql=&quot;delete from sess where sess_id=&apos;$sess_id&apos;&quot;;</div><div class="line">	return mysql_query($sql);</div><div class="line">&#125;</div><div class="line">/**</div><div class="line">*垃圾回收</div><div class="line">*超过生命周期的会话都是垃圾</div><div class="line">*/</div><div class="line">function gc($maxlifetime) &#123;</div><div class="line">	$time=time()-$maxlifetime;</div><div class="line">	$sql=&quot;delete from sess where sess_expires&lt;$time&quot;;</div><div class="line">	return mysql_query($sql);</div><div class="line">&#125;</div><div class="line"></div><div class="line">//更改会话的存储</div><div class="line">session_set_save_handler(&apos;open&apos;,&apos;close&apos;,&apos;read&apos;,&apos;write&apos;,&apos;destroy&apos;,&apos;gc&apos;);</div><div class="line">session_start();</div><div class="line">$_SESSION[&apos;sex&apos;]=100;</div><div class="line">echo $_SESSION[&apos;sex&apos;];</div><div class="line">session_destroy();</div><div class="line">?&gt;</div></pre></td></tr></table></figure>
<hr>
<blockquote>
<p>session_set_save_handler()必须放在session_start()前面才能起作用</p>
</blockquote>
<h1 id="COOKIE-与-SESSION的区别"><a href="#COOKIE-与-SESSION的区别" class="headerlink" title="COOKIE 与 SESSION的区别"></a>COOKIE 与 SESSION的区别</h1><p>cookie将键值存储在浏览器上<br>session将键存储在浏览器上，值存储在服务器上。</p>
<blockquote>
<p>cookie的可以被禁用的，禁用cookie，基于cookie的所有技术都无法使用。</p>
</blockquote>
<p>默认情况下，session是基于的cookie的，可以通过配置更改。</p>
<p><code>session.use_trans_sid=1</code><br><code>session.use_only_cookies=0</code></p>
<p>重启Apache会发现，会话编号不保存到cookie中，而是保存到get提交的URL中或表单的隐藏域中。</p>
<blockquote>
<p>已知session_set_save_handler()必须在session_start()前面开启，如果在php.ini中设置了session.auto_start = 1后，则session_set_save_handler()无效。如何处理？<br>在分布式部署文件中有两个指令来更改php.ini中的配置<br>php_flag：用来更改开关性质的配置<br>php_value：用来更改值性质的配置<br>php_flag session.auto_start 0<br>php_value session.gc_maxlifetime 10<br>将以上命令添置在.htaccess文件中</p>
</blockquote>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/20160924-2.html" itemprop="url">
                  初识Linux
                </a>
              
            
          </h1>
        

        <div class="post-meta">
        
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-09-24T14:06:41+08:00" content="2016-09-24">
              2016-09-24
            </time>
          </span>

          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/20160924-2.html#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="20160924-2.html" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="Linux目录结构"><a href="#Linux目录结构" class="headerlink" title="Linux目录结构"></a>Linux目录结构</h2><p>bin 和 sbin  ：存放命令的<br>/dev        ：存放外设文件<br>/etc        ：存放配置文件<br>/home       ：普通用户的家目录(主目录)<br>/root       ：超级管理员的家目录<br>/mnt        ：挂载点<br>/usr        ：安装程序<br>/var        ：相当于D、E盘，用来存储一些文件站点</p>
<h2 id="Linux常用命令"><a href="#Linux常用命令" class="headerlink" title="Linux常用命令"></a>Linux常用命令</h2><p>passwd    更改密码<br>ls    、ls -al *.png    查看目录中的内容<br>cd    进入目录<br>exit    退出当前工作环境<br>pwd    获取当前工作目录<br>su或su -    获取管理员权限<br>su - uiste    获取普通用户的权限<br>runlevel    获取运行级别<br>init N    改变运行等级<br>startx 和init5    启动图形化界面<br>clear    清空终端</p>
<h2 id="Linux命令格式"><a href="#Linux命令格式" class="headerlink" title="Linux命令格式"></a>Linux命令格式</h2><p>语法：名利 [-选项] 参数<br>Linux 命令是区分大小写的</p>
<h2 id="查看文件的详细信息-ls-al"><a href="#查看文件的详细信息-ls-al" class="headerlink" title="查看文件的详细信息(ls -al)"></a>查看文件的详细信息(ls -al)</h2><p>-a  显示所有文件<br>-l  显示详细信息<br><img src="media/14746901645222/14746929569559.jpg" alt=""><br>pwd    显示当前目录<br>ls    显示当前目录的文件<br>ls -l    列出文件的详细信息<br>ls -a    列出所有文件，包括隐藏文件<br>ls -al    后面是查询选择，查询选项是没有先后顺序的</p>
<h2 id="常用指令"><a href="#常用指令" class="headerlink" title="常用指令"></a>常用指令</h2><p>dir             显示当前目录的所有文件<br>who am  i       显示登录的用户名<br>whoami          显示当前使用谁的权限<br>exit  、q        退出权限系统<br>halt            关闭计算机<br>power off       关闭计算机<br>reboot          重启计算机<br>man             查看帮助文档 manual<br>–help、-help    调用命令的注释帮助</p>
<h2 id="显示目录所占磁盘容量-du"><a href="#显示目录所占磁盘容量-du" class="headerlink" title="显示目录所占磁盘容量(du)"></a>显示目录所占磁盘容量(du)</h2><p>du file/dir 显示文件或文件夹的容量，单位是KB，如果是文件夹显示文件夹中每个文件额大小和总大小<br>du -s dir 显示文件夹的总大小，不显示文件夹中文件大小<br>du -h file/dir 用友好的方式显示容量</p>
<h2 id="改变工作目录-cd"><a href="#改变工作目录-cd" class="headerlink" title="改变工作目录(cd)"></a>改变工作目录(cd)</h2><p>语法：cd 目录</p>
<table>
<thead>
<tr>
<th>cd dir</th>
<th>进入dir文件夹下</th>
</tr>
</thead>
<tbody>
<tr>
<td>cd ..</td>
<td>..表示上一级</td>
</tr>
<tr>
<td>cd ../dir</td>
<td>进入上一级目录中的dir文件夹下</td>
</tr>
<tr>
<td>cd /dir</td>
<td>通过绝对路径进入到dir文件夹下</td>
</tr>
<tr>
<td>cd ~</td>
<td>进入个人主目录</td>
</tr>
<tr>
<td>cd</td>
<td>cd后面不跟参数就进入到个人主目录，和cd ~一样</td>
</tr>
</tbody>
</table>
<h2 id="目录操作"><a href="#目录操作" class="headerlink" title="目录操作"></a>目录操作</h2><h3 id="创建目录-mkdir"><a href="#创建目录-mkdir" class="headerlink" title="创建目录(mkdir)"></a>创建目录(mkdir)</h3><table>
<thead>
<tr>
<th>mkdir dir1</th>
<th>在当前目录下创建dir1文件夹</th>
</tr>
</thead>
<tbody>
<tr>
<td>mkdir dir1/dir2</td>
<td>在dir1目录下创建dir2目录（dir1必须存在)</td>
</tr>
<tr>
<td>mkdir -p dir1/dir2</td>
<td>如果没有dir1，先创建dir1再创建dir2. -p 可以写在后面</td>
</tr>
<tr>
<td>mk dir1 dir2 .</td>
<td>同时创建dir1、dir2、dir3…</td>
</tr>
</tbody>
</table>
<h3 id="删除目录-rmdir"><a href="#删除目录-rmdir" class="headerlink" title="删除目录(rmdir)"></a>删除目录(rmdir)</h3><table>
<thead>
<tr>
<th>rmdir dir</th>
<th>删除目录，如果目标不为空这报错，不能删除</th>
</tr>
</thead>
<tbody>
<tr>
<td>rmdir dir1 dir2</td>
<td>同时删除多个目录</td>
</tr>
</tbody>
</table>
<h3 id="既能删除文件也能删除目录-rm"><a href="#既能删除文件也能删除目录-rm" class="headerlink" title="既能删除文件也能删除目录(rm)"></a>既能删除文件也能删除目录(rm)</h3><blockquote>
<p>-r recursieve 递归<br>-f force 强制</p>
</blockquote>
<table>
<thead>
<tr>
<th>rm file</th>
<th>删除文件</th>
</tr>
</thead>
<tbody>
<tr>
<td>rm -rf file/dir</td>
<td>删除文件和文件夹</td>
</tr>
</tbody>
</table>
<h2 id="复制文件和目录-cp"><a href="#复制文件和目录-cp" class="headerlink" title="复制文件和目录(cp)"></a>复制文件和目录(cp)</h2><p>语法：cp [-r/-R] 源地址 目标地址</p>
<table>
<thead>
<tr>
<th>cp file dir</th>
<th>将file文件拷贝到dir文件夹下</th>
</tr>
</thead>
<tbody>
<tr>
<td>cp file1 dir/file2</td>
<td>将file1拷贝到dir文件夹下并改名为file2</td>
</tr>
<tr>
<td>cp file1 file2</td>
<td>将file1复制一份，重命名为file2</td>
</tr>
<tr>
<td>cp -R/-r dir1 dir2</td>
<td>将dir1文件夹递归复制到dir2文件夹下</td>
</tr>
</tbody>
</table>
<h2 id="移动文件或目录-mv"><a href="#移动文件或目录-mv" class="headerlink" title="移动文件或目录(mv)"></a>移动文件或目录(mv)</h2><table>
<thead>
<tr>
<th>mv file dir</th>
<th>将file文件移动到dir文件夹下</th>
</tr>
</thead>
<tbody>
<tr>
<td>mv dir1 dir2</td>
<td>dir2不存在就是该文件夹名字 dir2存在就是将dir1移动到dir2文件夹下</td>
</tr>
<tr>
<td>mv file1 file2</td>
<td>将file1的名字改为file2</td>
</tr>
<tr>
<td>mv dir1 dir2/dir3</td>
<td>将dir1拷贝到dir2文件夹下，并改名为dir3</td>
</tr>
</tbody>
</table>
<h2 id="文件查看"><a href="#文件查看" class="headerlink" title="文件查看"></a>文件查看</h2><table>
<thead>
<tr>
<th>cat 文件名</th>
<th>一次性查看全部内容</th>
</tr>
</thead>
<tbody>
<tr>
<td>more 文件名</td>
<td>分屏显示，按回车向下翻，一旦下翻就不能上翻</td>
</tr>
<tr>
<td>less 文件名</td>
<td>允许上翻和下翻，按向上和向下的键</td>
</tr>
<tr>
<td>head -n 文件名</td>
<td>显示前n条记录</td>
</tr>
<tr>
<td>tail -n 文件名</td>
<td>显示后几条</td>
</tr>
<tr>
<td>wc 文件名</td>
<td>用来计算文件行数、句数、字符数</td>
</tr>
</tbody>
</table>
<h2 id="新建文件和添加内容"><a href="#新建文件和添加内容" class="headerlink" title="新建文件和添加内容"></a>新建文件和添加内容</h2><h3 id="新建文件-touch"><a href="#新建文件-touch" class="headerlink" title="新建文件(touch)"></a>新建文件(touch)</h3><table>
<thead>
<tr>
<th>touch 文件名</th>
<th>新建一个文件</th>
</tr>
</thead>
<tbody>
<tr>
<td>touch file1 file2 …</td>
<td>一次新建多个文件</td>
</tr>
<tr>
<td>touch dir/file</td>
<td>在dir文件夹下新建file文件</td>
</tr>
</tbody>
</table>
<h3 id="添加内容-echo、cat"><a href="#添加内容-echo、cat" class="headerlink" title="添加内容(echo、cat)"></a>添加内容(echo、cat)</h3><table>
<thead>
<tr>
<th>echo 内容&gt;文件</th>
<th>将内容写入到文件（清空写），如果文件不存在则创建新文件</th>
</tr>
</thead>
<tbody>
<tr>
<td>echo 内容&gt;&gt;文件</td>
<td>和上面一样，（追加内容）</td>
</tr>
<tr>
<td>cat file1&gt;file2</td>
<td>将file1的内容写到file2中（清空写）（文件不存在则创建）</td>
</tr>
<tr>
<td>cat file1&gt;&gt;file2</td>
<td>和上面一样，（追加内容）</td>
</tr>
<tr>
<td>cat file1 file2 &gt; file3</td>
<td>将file1和file2的内容合并成file3</td>
</tr>
</tbody>
</table>
<blockquote>
<p>>是清空写<br>>&gt;追加写<br>写入&gt;字符时，使用引号，或者\ 反斜杠，进行转义</p>
</blockquote>
<h2 id="组-group-的操作"><a href="#组-group-的操作" class="headerlink" title="组(group)的操作"></a>组(group)的操作</h2><table>
<thead>
<tr>
<th>groupadd 组名</th>
<th>添加组</th>
</tr>
</thead>
<tbody>
<tr>
<td>grouped -n 新组名 旧组名</td>
<td>修改组</td>
</tr>
<tr>
<td>grouped 组名</td>
<td>删除组</td>
</tr>
</tbody>
</table>
<blockquote>
<p>查看组：cat ../etc/group</p>
</blockquote>
<h2 id="用户（user）的操作"><a href="#用户（user）的操作" class="headerlink" title="用户（user）的操作"></a>用户（user）的操作</h2><blockquote>
<p>用户信息都保存在<code>/etc/passwd</code> 文件中 <code>cat ../etc/passwd</code><br><code>uiste:x:500:500::/home/uiste:/bin/bash</code><br>用户名：口令：用户id号：组的id号：注释性描述：家目录：登录shell</p>
</blockquote>
<h3 id="添加用户（useradd）"><a href="#添加用户（useradd）" class="headerlink" title="添加用户（useradd）"></a>添加用户（useradd）</h3><table>
<thead>
<tr>
<th>命令</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>useradd 用户名</td>
<td>创建用户，在创建的时候自动创建组</td>
</tr>
<tr>
<td>useradd 用户名 -g 组编号</td>
<td>在相应的组下创建用户</td>
</tr>
<tr>
<td>useradd 用户名 -u 用户编号</td>
<td>给创建的用户指定用户编号</td>
</tr>
<tr>
<td>useradd 用户名 -d 家目录</td>
<td>给用户指定家目录</td>
</tr>
</tbody>
</table>
<h3 id="修改用户（usermod）"><a href="#修改用户（usermod）" class="headerlink" title="修改用户（usermod）"></a>修改用户（usermod）</h3><table>
<thead>
<tr>
<th>命令</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>usermod -l 新用户名 旧用户名</td>
<td>修改用户名</td>
</tr>
<tr>
<td>usermod -u 用户编号 用户名</td>
<td>修改用户编号</td>
</tr>
<tr>
<td>usermod -g 组的编号 用户名</td>
<td>修改用户的组</td>
</tr>
<tr>
<td>usermod -d 家目录 用户名</td>
<td>修改家目录</td>
</tr>
</tbody>
</table>
<h3 id="删除用户（userdel）"><a href="#删除用户（userdel）" class="headerlink" title="删除用户（userdel）"></a>删除用户（userdel）</h3><table>
<thead>
<tr>
<th>命令</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>userdel 用户名</td>
<td>删除用户，家目录还存在</td>
</tr>
<tr>
<td>userdel -r 用户名</td>
<td>删除用户同时删除家目录</td>
</tr>
</tbody>
</table>
<h2 id="常用指令-1"><a href="#常用指令-1" class="headerlink" title="常用指令"></a>常用指令</h2><table>
<thead>
<tr>
<th>命令</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>grep string [file]</td>
<td>在字符串中查找</td>
</tr>
<tr>
<td>ps -A</td>
<td>（process）查询所有进程</td>
</tr>
<tr>
<td>kill —9 pid</td>
<td>杀死指定进程</td>
</tr>
<tr>
<td>df -lh</td>
<td>参看系统分区</td>
</tr>
</tbody>
</table>
<h2 id="date"><a href="#date" class="headerlink" title="date"></a>date</h2><table>
<thead>
<tr>
<th>命令</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>date</td>
<td>显示系统时间</td>
</tr>
<tr>
<td>date -s ‘2015-11-6 11:11:11’</td>
<td>更改系统时间</td>
</tr>
</tbody>
</table>
<h2 id="管道"><a href="#管道" class="headerlink" title="管道(|)"></a>管道(|)</h2><h2 id="查找文件（find）"><a href="#查找文件（find）" class="headerlink" title="查找文件（find）"></a>查找文件（find）</h2><table>
<thead>
<tr>
<th>命令</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>find / -name passwd</td>
<td>查找根下所有passwd的文件[区分大小写]</td>
</tr>
<tr>
<td>find / -iname passwd</td>
<td>查找根下所有passwd的文件[不区分大小写]</td>
</tr>
<tr>
<td>find / -mindepth 3 -name passwd</td>
<td>在最低3层目录下查找passwd文件</td>
</tr>
<tr>
<td>find / -maxdepth 2 -name passwd</td>
<td>在最高2层目录下查找passwd文件</td>
</tr>
<tr>
<td>find . -iname *.c</td>
<td>在当前目录下查找以.c结尾的文件，不区分大小写</td>
</tr>
<tr>
<td>find / -size +50k</td>
<td>搜索大于50K的文件</td>
</tr>
<tr>
<td>find / -size -40c</td>
<td>搜索小鱼40字节的文件char</td>
</tr>
<tr>
<td>find . -type f</td>
<td>查找当前目录下的所有文件</td>
</tr>
<tr>
<td>find . -type d</td>
<td>查找当前目录下所有的文件夹</td>
</tr>
</tbody>
</table>
<h2 id="软连接和硬连接"><a href="#软连接和硬连接" class="headerlink" title="软连接和硬连接"></a>软连接和硬连接</h2><h3 id="软连接"><a href="#软连接" class="headerlink" title="软连接"></a>软连接</h3><p>软连接就是快捷方式<br>语法：ln -s 源文件 连接文件</p>
<h3 id="硬连接"><a href="#硬连接" class="headerlink" title="硬连接"></a>硬连接</h3><p>语法：ln 源文件 连接文件<br>查看：ls -li 查看文件的索引编号</p>
<blockquote>
<p>在Linux中删除文件并不是件文件本身删除，而是删除文件的索引，文件是垃圾回收机制来删除<br>只有文件才能做硬连接</p>
</blockquote>
<h2 id="权限（rwx-）"><a href="#权限（rwx-）" class="headerlink" title="权限（rwx-）"></a>权限（rwx-）</h2><p>Linux的权限有3种：读权限（read）、写权限（write）、可执行权限（execute）<br>文件属性部分有10个字符组成，第一个字符是表示文件的类型，后面还剩下9个字符，每3个一组（每组由读、写、可执行组成），分成3组，第一组是文件所有者（user）的权限，第二组是和文件所有者同组（group）的权限，第三组其他用户（other）的权限</p>
<h3 id="常用便是文件的字符"><a href="#常用便是文件的字符" class="headerlink" title="常用便是文件的字符"></a>常用便是文件的字符</h3><table>
<thead>
<tr>
<th>b</th>
<th>系统设备文件，使用i/o与外界交互的设备，通常是磁盘</th>
</tr>
</thead>
<tbody>
<tr>
<td>d</td>
<td>表示文件夹</td>
</tr>
<tr>
<td>-</td>
<td>表示文件</td>
</tr>
<tr>
<td>l</td>
<td>连接文件</td>
</tr>
<tr>
<td>c</td>
<td>系统设备文件，利用串口设备和声音</td>
</tr>
</tbody>
</table>
<h3 id="更新权限"><a href="#更新权限" class="headerlink" title="更新权限"></a>更新权限</h3><p>语法：chmod 权限 file/dir</p>
<table>
<thead>
<tr>
<th>案例</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>chmod u+x,o+rx dir</td>
<td>用户添加可执行权限，其他用户添加读、可执行权限</td>
</tr>
<tr>
<td>chmod u+rwx,o-r file</td>
<td>用户添加读、写、可执行，其他用户去掉读权限</td>
</tr>
<tr>
<td>chmod go -rwx file</td>
<td>组和其他用户去掉读、写、可执行权限</td>
</tr>
<tr>
<td>chmod 750 file</td>
<td>通过数字来设置权限</td>
</tr>
</tbody>
</table>
<h2 id="更改文件所有者和组"><a href="#更改文件所有者和组" class="headerlink" title="更改文件所有者和组"></a>更改文件所有者和组</h2><h3 id="更改所有者（chown）"><a href="#更改所有者（chown）" class="headerlink" title="更改所有者（chown）"></a>更改所有者（chown）</h3><table>
<thead>
<tr>
<th>chown user file</th>
<th>将file改成user用户</th>
</tr>
</thead>
<tbody>
<tr>
<td>chown -R user dir</td>
<td>将dir文件中的所有文件所有者改为user</td>
</tr>
</tbody>
</table>
<h3 id="更改组（chgrp）"><a href="#更改组（chgrp）" class="headerlink" title="更改组（chgrp）"></a>更改组（chgrp）</h3><p>语法一：chgrp [-R] 新组名 file/dir<br>将file 或 dir 更改新组名<br>语法二：chown 用户名.组名 文件</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">chown  user passwd        将passwd更改为user所有</div><div class="line">chown  .php passwd        将passwd更改为php组所有</div><div class="line">chown  user.php passwd    将passwd更改为php组的user所有</div></pre></td></tr></table></figure>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/20160924-1.html" itemprop="url">
                  Vim（VI）
                </a>
              
            
          </h1>
        

        <div class="post-meta">
        
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-09-24T12:05:39+08:00" content="2016-09-24">
              2016-09-24
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/Linux/" itemprop="url" rel="index">
                    <span itemprop="name">Linux</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/20160924-1.html#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="20160924-1.html" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h1 id="Vim-VI-介绍"><a href="#Vim-VI-介绍" class="headerlink" title="Vim(VI)介绍"></a>Vim(VI)介绍</h1><p>Vim（vi）是Linux提供的一个更改文件的工具。</p>
<h2 id="Vi有3种模式："><a href="#Vi有3种模式：" class="headerlink" title="Vi有3种模式："></a>Vi有3种模式：</h2><p>命令模式、尾行模式、编辑模式<br><img src="media/14744245835193/14746880050755.jpg" alt=""></p>
<h2 id="尾行模式"><a href="#尾行模式" class="headerlink" title="尾行模式"></a>尾行模式</h2><table>
<thead>
<tr>
<th>:</th>
<th>进入尾行模式</th>
</tr>
</thead>
<tbody>
<tr>
<td>:w</td>
<td>保存</td>
</tr>
<tr>
<td>:w!</td>
<td>强制保存</td>
</tr>
<tr>
<td>:q</td>
<td>退出</td>
</tr>
<tr>
<td>:q!</td>
<td>强制退出</td>
</tr>
<tr>
<td>:wq</td>
<td>保存并退出</td>
</tr>
<tr>
<td>:wq!</td>
<td>强制保存并退出</td>
</tr>
<tr>
<td>set number 或 set nu</td>
<td>设置行号</td>
</tr>
<tr>
<td>set nonumber 或 set nonu</td>
<td>取消行号</td>
</tr>
<tr>
<td>u</td>
<td>撤销上一条命令</td>
</tr>
<tr>
<td>.</td>
<td>重复最后一条命令</td>
</tr>
<tr>
<td>J</td>
<td>连接上下两行</td>
</tr>
<tr>
<td>r+w</td>
<td>将当前的字母替换成w</td>
</tr>
<tr>
<td>:n</td>
<td>跳转到第n行</td>
</tr>
<tr>
<td>:/str 或 /str</td>
<td>从上往下搜索str n 下一个 N 上一个</td>
</tr>
<tr>
<td>?str</td>
<td>从下往上搜索str</td>
</tr>
<tr>
<td>:s/str/aa</td>
<td>将str替换成aa</td>
</tr>
<tr>
<td>:s/str/aa/g</td>
<td>将一行的所有str替换成aa</td>
</tr>
<tr>
<td>:%s/str/aa/g</td>
<td>将整个页面的str替换成aa</td>
</tr>
</tbody>
</table>
<h2 id="编辑模式"><a href="#编辑模式" class="headerlink" title="编辑模式"></a>编辑模式</h2><table>
<thead>
<tr>
<th>i</th>
<th style="text-align:left">在当前位置上插入，原来位置上字符后移</th>
</tr>
</thead>
<tbody>
<tr>
<td>a</td>
<td style="text-align:left">光标先后移动一位插入</td>
</tr>
<tr>
<td>o</td>
<td style="text-align:left">新起一个空白行插入</td>
</tr>
<tr>
<td>s</td>
<td style="text-align:left">删除光标所在字符再插入</td>
</tr>
</tbody>
</table>
<h2 id="命令模式"><a href="#命令模式" class="headerlink" title="命令模式"></a>命令模式</h2><h3 id="移动光标"><a href="#移动光标" class="headerlink" title="移动光标"></a>移动光标</h3><table>
<thead>
<tr>
<th>⬆️</th>
<th>⬇️</th>
<th>⬅️</th>
<th>➡️</th>
</tr>
</thead>
<tbody>
<tr>
<td>k</td>
<td>j</td>
<td>h</td>
<td>l</td>
</tr>
</tbody>
</table>
<h3 id="单词级别"><a href="#单词级别" class="headerlink" title="单词级别"></a>单词级别</h3><table>
<thead>
<tr>
<th>e</th>
<th>本单词的末尾，如果当前光标就在本单词末尾就跳转到下个单词的末尾</th>
</tr>
</thead>
<tbody>
<tr>
<td>b</td>
<td>本单词的首字母，如果当前光标就在本单词的首字母上就跳到上一个单词的首字母</td>
</tr>
<tr>
<td>w</td>
<td>跳转到下一个单词的首字母</td>
</tr>
</tbody>
</table>
<h3 id="行级"><a href="#行级" class="headerlink" title="行级"></a>行级</h3><table>
<thead>
<tr>
<th>$</th>
<th>调到行尾</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>调到行首</td>
</tr>
</tbody>
</table>
<h3 id="段级"><a href="#段级" class="headerlink" title="段级"></a>段级</h3><table>
<thead>
<tr>
<th>{</th>
<th>段首</th>
</tr>
</thead>
<tbody>
<tr>
<td>}</td>
<td>段尾</td>
</tr>
</tbody>
</table>
<h3 id="屏幕级"><a href="#屏幕级" class="headerlink" title="屏幕级"></a>屏幕级</h3><table>
<thead>
<tr>
<th>H</th>
<th>屏幕的首部</th>
</tr>
</thead>
<tbody>
<tr>
<td>L</td>
<td>屏幕的尾部</td>
</tr>
</tbody>
</table>
<h3 id="文档级"><a href="#文档级" class="headerlink" title="文档级"></a>文档级</h3><table>
<thead>
<tr>
<th>nG</th>
<th>跳转到第n行</th>
</tr>
</thead>
<tbody>
<tr>
<td>G</td>
<td>移动到文档尾部</td>
</tr>
</tbody>
</table>
<h2 id="删除操作"><a href="#删除操作" class="headerlink" title="删除操作"></a>删除操作</h2><table>
<thead>
<tr>
<th>x</th>
<th>删除当前的字符</th>
</tr>
</thead>
<tbody>
<tr>
<td>dd</td>
<td>删除当前行</td>
</tr>
<tr>
<td>3dd</td>
<td>删除3行</td>
</tr>
<tr>
<td>d+e</td>
<td>表示从光标开始删除，删除到单词末尾或下一个单词末尾</td>
</tr>
<tr>
<td>d+$</td>
<td>删除从光标开始到这行结束</td>
</tr>
</tbody>
</table>
<h2 id="复制操作"><a href="#复制操作" class="headerlink" title="复制操作"></a>复制操作</h2><table>
<thead>
<tr>
<th>yy</th>
<th>复制当前行</th>
</tr>
</thead>
<tbody>
<tr>
<td>p</td>
<td>粘贴</td>
</tr>
<tr>
<td>3yy</td>
<td>复制3行</td>
</tr>
<tr>
<td>y+e</td>
<td>从光标开始复制，复制到单词结束或下一个单词结束</td>
</tr>
</tbody>
</table>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/4/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/4/">4</a><span class="page-number current">5</span><a class="page-number" href="/page/6/">6</a><span class="space">&hellip;</span><a class="page-number" href="/page/14/">14</a><a class="extend next" rel="next" href="/page/6/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      

      <section class="site-overview sidebar-panel  sidebar-panel-active ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.png"
               alt="uiste" />
          <p class="site-author-name" itemprop="name">uiste</p>
          <p class="site-description motion-element" itemprop="description">Stay Hungry，Stay Foolish</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">70</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">13</span>
                <span class="site-state-item-name">分类</span>
              
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">55</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/uiste" target="_blank" rel="external nofollow" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/uiste" target="_blank" rel="external nofollow" title="微博">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  微博
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://www.zhihu.com/people/uiste" target="_blank" rel="external nofollow" title="知乎">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  知乎
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              友情链接
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.uiste.com" title="uiste 个人博客" target="_blank">uiste 个人博客</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://uiste.github.io" title="uiste 技术博客" target="_blank">uiste 技术博客</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2015 - 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">uiste</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="http://hexo.io" rel="external nofollow">Hexo</a> 趋势动力
</div>
<!--站长统计-->
<script src="https://s95.cnzz.com/z_stat.php?id=1259894121&web_id=1259894121" language="JavaScript"></script>
<!--<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next" rel="external nofollow">
    NexT.Mist
  </a>
</div> -->
&nbsp;&nbsp;&nbsp;本站总点击 <span id="busuanzi_value_site_pv"></span> 次
&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;您是第 <span id="busuanzi_value_site_uv"></span> 位访客

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
</script>

<script>
(function(){
    var bp = document.createElement('script');
    bp.src = '//push.zhanzhang.baidu.com/push.js';
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  

  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"uiste"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    <script src="/vendors/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  






  
  
  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
       search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body").append('<div class="popoverlay">').css('overflow', 'hidden');
      $('.popup').toggle();

    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
    'use strict';
    $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
            // get the contents from search data
            isfetched = true;
            $('.popup').detach().appendTo('.header-inner');
            var datas = $( "entry", xmlResponse ).map(function() {
                return {
                    title: $( "title", this ).text(),
                    content: $("content",this).text(),
                    url: $( "url" , this).text()
                };
            }).get();
            var $input = document.getElementById(search_id);
            var $resultContent = document.getElementById(content_id);
            $input.addEventListener('input', function(){
                var matchcounts = 0;
                var str='<ul class=\"search-result-list\">';
                var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                $resultContent.innerHTML = "";
                if (this.value.trim().length > 1) {
                // perform local searching
                datas.forEach(function(data) {
                    var isMatch = true;
                    var content_index = [];
                    var data_title = data.title.trim().toLowerCase();
                    var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                    var data_url = data.url;
                    var index_title = -1;
                    var index_content = -1;
                    var first_occur = -1;
                    // only match artiles with not empty titles and contents
                    if(data_title != '' && data_content != '') {
                        keywords.forEach(function(keyword, i) {
                            index_title = data_title.indexOf(keyword);
                            index_content = data_content.indexOf(keyword);
                            if( index_title < 0 && index_content < 0 ){
                                isMatch = false;
                            } else {
                                if (index_content < 0) {
                                    index_content = 0;
                                }
                                if (i == 0) {
                                    first_occur = index_content;
                                }
                            }
                        });
                    }
                    // show search results
                    if (isMatch) {
                        matchcounts += 1;
                        str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                        var content = data.content.trim().replace(/<[^>]+>/g,"");
                        if (first_occur >= 0) {
                            // cut out 100 characters
                            var start = first_occur - 20;
                            var end = first_occur + 80;
                            if(start < 0){
                                start = 0;
                            }
                            if(start == 0){
                                end = 50;
                            }
                            if(end > content.length){
                                end = content.length;
                            }
                            var match_content = content.substring(start, end);
                            // highlight all keywords
                            keywords.forEach(function(keyword){
                                var regS = new RegExp(keyword, "gi");
                                match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                            });

                            str += "<p class=\"search-result\">" + match_content +"...</p>"
                        }
                        str += "</li>";
                    }
                })};
                str += "</ul>";
                if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
                if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
                $resultContent.innerHTML = str;
            });
            proceedsearch();
        }
    });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };

    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".popoverlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>


  

  

  

</body>
</html>
